<template>
  <div class="app-container">
    <el-form ref="elFormSetting" :model="formSettingData" :rules="rules" size="medium" label-width="120px">
      <el-form-item label="信令服务器地址" prop="sip_command_host">
        <el-input
          v-model="formSettingData.sip_command_host"
          placeholder="请输入服务器地址服务器地址"
          :maxlength="256"
          show-word-limit
          clearable
          prefix-icon="el-icon-mobile"
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="信令服务端口" prop="sip_command_port">
        <el-input
          v-model="formSettingData.sip_command_port"
          placeholder="输入信令服务端口"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="服务器SIP帐号" prop="sip_command_account">
        <el-input
          v-model="formSettingData.sip_command_account"
          placeholder="请输入服务器SIP帐号"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="服务器域" prop="server_realm">
        <el-input
          v-model="formSettingData.server_realm"
          placeholder="请输入服务器域"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="验证密码" prop="sip_command_password">
        <el-input
          v-model="formSettingData.sip_command_password"
          placeholder="请输入验证密码"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="心跳时长(秒)" prop="keep_alive_second">
        <el-input
          v-model="formSettingData.keep_alive_second"
          placeholder="心跳时长"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <el-form-item label="抓图保存地址" prop="snap_path">
        <el-input
          v-model="formSettingData.snap_path"
          placeholder="./public/static/snap/"
          clearable
          :style="{width:'100%'}"
        />
      </el-form-item>
      <!--级联设置-->
      <el-form-item label="上级国标地址" prop="upper_host">
        <el-input
          v-model="formSettingData.upper_host"
          placeholder="请输入上级国标服务器地址"
          :maxlength="256"
          show-word-limit
          clearable
          prefix-icon="el-icon-mobile"
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="上级国标端口" prop="upper_port">
        <el-input
          v-model="formSettingData.upper_port"
          placeholder="请输入上级国标服务器端口"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="上级国标域" prop="upper_realm">
        <el-input
          v-model="formSettingData.upper_realm"
          placeholder="请输入上级国标服务器域"
          clearable
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="验证密码" prop="upper_password">
        <el-input
          v-model="formSettingData.upper_password"
          placeholder="请输入上级国标验证密码"
          :maxlength="256"
          show-word-limit
          clearable
          prefix-icon="el-icon-mobile"
          :style="{width: '100%'}"
        />
      </el-form-item>
      <el-form-item label="心跳时间" prop="keep_alive_second">
        <el-input
          v-model="formSettingData.keep_alive_second"
          placeholder="请输入上级国标心跳时间"
          :maxlength="256"
          show-word-limit
          clearable
          prefix-icon="el-icon-heart"
          :style="{width: '100%'}"
        />
      </el-form-item>
      <!--级联代码结束-->
      <el-form-item size="large">
        <el-button type="primary" :loading="loading" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { load } from '@/api/setting'
export default {
  name: 'Setting',
  components: {},
  props: [],
  data() {
    return {
      formSettingData: {
        sip_command_host: undefined,
        sip_command_port: undefined,
        server_realm: undefined,
        sip_command_password: undefined,
        keep_alive_second: 60
      },
      loading: false,
      rules: {
        sip_command_host: [{ required: true, message: '请输入信令服务器地址', trigger: 'blur' }],
        sip_command_port: [{ required: true, message: '请输入信令服务端口', trigger: 'blur' }],
        server_realm: [{ required: true, message: '请输入服务器域', trigger: 'blur' }],
        sip_command_password: [{ required: true, message: '请输入验证密码', trigger: 'blur' }],
        keep_alive_second: [{ required: true, message: '请输入心跳时间', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.fetchData()
  },
  mounted() {},
  methods: {
    fetchData() {
      load().then(ret => {
        console.log('ret.data', ret.data)
        this.formSettingData = ret.data
      })
    },
    submitForm() {
      this.$refs['elFormSetting'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('setting/save', this.formSettingData).then(() => {
            // this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch((err) => {
            console.error(err)
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })
    },
    resetForm() {
      this.$refs['elFormSetting'].resetFields()
    }
  }
}

</script>
<style>
</style>
